#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int f(ll x) {
	int res = 0;
	while (x > 0) {
		res++;
		x /= 10;
	}
	return res;
}

int ksm(int x) {
	int res = 1;
	while (x > 0) {
		res *= 10;
		x--;
	}
	return res;
}

void solve() {
	ll n, a, b, m;
	cin >> n >> a >> b >> m;
	ll tmp = a;
	ll ans = a;
	for (int i = 1; i <= n; i++) {
		tmp += b;
		ans = ans * ksm(f(tmp)) + tmp;
	}
	cout << ans % m << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}